package com.company.linkedList;

public class DeleteDuplicates {

    public ListNode deleteDuplicates(ListNode head) {
        ListNode node = head;


        boolean inRemove=false;

        ListNode beginNode=null;
        ListNode endNode=null;
        ListNode preNode=null;

        while (node!=null&&node.next!=null){
            if(node.val == node.next.val){
                inRemove=true;
                beginNode = node;
                endNode = node.next;
            }else {
                //移除
                if (preNode == null) {
                    head = node.next;
                }else {
                    preNode.next = node.next;
                }
                inRemove = false;
            }
            preNode = node;
            node = node.next;
        }

        return head;

    }
}
